<template>
  <div>
    <div>
      <el-input v-model="params.name" style="width: 200px" placeholder="请输入操作内容"></el-input>
      <el-button @click="findBysearch()">查询</el-button>
      <el-button type="warning" @click="reset()">清空</el-button>
    </div>


    <div>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="name" label="操作内容"></el-table-column>
        <el-table-column prop="time" label="操作时间"></el-table-column>
        <el-table-column prop="username" label="操作人"></el-table-column>
        <el-table-column prop="ip" label="ip"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-popconfirm title="确定删除吗？" @confirm="del(scope.row.id)">
              <el-button slot="reference" type="danger" style="margin-left: 5px">删除</el-button>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
    </div>

<!--    分页-->
    <div class="block" style="margin-left: 100px">

        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="params.pageNum"
            :page-sizes="[5, 10, 15, 20]"
            :page-size="params.pageSize"
            layout="total, sizes, prev, pager, next"
            :total="total">
        </el-pagination>

    </div>


  </div>
</template>

<script>
import Request from "@/utils/request";

export default {
  data() {
    return {
      params:{
        id:'',
        userName:'',
        pageNum:1,
        pageSize:5
      },
      tableData: [],
      total:0,
      dialogFormVisible:false,
      form:{},
      user:localStorage.getItem("user")?JSON.parse(localStorage.getItem("user")):{}
    }
  },
  // 页面加载的时候做的一些事情
  created() {
   this.findBysearch()
  },
  // 定义的方法在这里写
  methods:{
    findBysearch(){
      Request.get("/log/search",{
        params:this.params
      }).then(res=>{
        if(res.code =='0' ){
          console.log(res)
          //调用成功信息
          this.tableData=res.data.list;
          this.total =res.data.total
        }else{
          // 调用失败信息
          this.$message({
            message:'res.msg',
            type:'success'
          })
        }
      })
    },
    reset(){
      this.params = {
        id:'',
        userName:'',
        pageNum:1,
        pageSize:5
      },
          // 清空后查询全部
          this.findBysearch()
    },
    add(){
        this.form = {}
        this.dialogFormVisible=true
    },
    edit(obj){
      this.form = obj
      this.dialogFormVisible=true
    },
    handleSizeChange(pageSize){
    this.params.pageSize = pageSize;
    this.findBysearch()
    },
    handleCurrentChange(pageNum){
      this.params.pageNum = pageNum;
      this.findBysearch()
    },
    submit(){
      Request.post("/log",this.form).then(res => {
        if(res.code == '0'){
          this.$message({
            message:'操作成功',
            type:'success'
          })
          this.dialogFormVisible=false
        }else {
          this.$message({
            message:res.msg,
            type:'error'
          })
        }
      })
    },
    del(id) {
      Request.delete("/log/" + id).then(res => {
        if (res.code === '0') {
          this.$message({
            message: '删除成功',
            type: 'success'
          });
          this.findBysearch()
        } else {
          this.$message({
            message: res.msg,
            type: 'success'
          });
        }
      })
    }
  }
}
</script>

<style>

</style>